package com.huaao.micropolice.core.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huaao.micropolice.core.common.page.Page;
import com.huaao.micropolice.core.model.system.Jobs;
import com.huaao.micropolice.core.repository.system.JobsDao;
import com.huaao.micropolice.core.service.system.JobsService;

@Service
@Transactional
public class JobsServiceImpl implements JobsService{
	@Autowired
	private JobsDao jobsDao;
 
	@Override
	public String save(Jobs obj) {
		return jobsDao.save(obj);
	}

	 

	@Override
	public List<Jobs> findByDeptId(String id) {
		// TODO Auto-generated method stub
		if(id == null){
			id = "0";
		}
		return jobsDao.findByDeptId(id);
	}

	@Override
	public void update(Jobs obj) {
		jobsDao.update(obj);
	}

	@Override
	public void del(String id) throws Exception  {
		Jobs job = (Jobs)jobsDao.load(Jobs.class, id);
		if( !job.getRoles().isEmpty() ){
			throw new Exception("["+job.getName()+"] 存在关联角色，无法删除");
		}
		jobsDao.deleteById(Jobs.class, id);
	}

	@Override
	public List<Jobs> findAll() {
		Page page = new Page();
		page.setPageSize(Integer.MAX_VALUE);
		return jobsDao.findByPage(Jobs.class, null, null, page );
	}
}
